const App = getApp();
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo:{},
    type:""
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that = this;
      var token = wx.getStorageSync('token');
      var type = wx.getStorageSync("type");
      this.setData({type:type})
      App._post_form('wxapi/myinfo', {
        token: token,
      
      }, result => {
        // 记录token user_id
        console.log("ss",result);

        that.setData({userinfo:result.data})

      }, false, () => {
        wx.hideLoading();
      });


  },
  user_exit:function(e){
    wx.showModal({
      title: '系统提示',
      content: '确定要注销吗！',
      cancelText: '返回',
      success: res => {
        if (res.confirm) {
          app.globalData.userInfo = null;
          wx.removeStorageSync('userInfo');
          wx.redirectTo({
            url: '/pages/user_login/user_login'
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (App.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  home:function(){
    wx.redirectTo({
      url: '/pages/order/index'
    })
  },
  exit:function(){
    wx.setStorageSync('token', "");
    wx.redirectTo({
      url: '/pages/index/index'
    })
  },
  getScancode:function(){
    wx.scanCode({
     onlyFromCamera: true,
     success: (res) => {
       console.log(res)
        var code = res.result;
        var token = wx.getStorageSync('token');
        App._post_form('wxapi/check', {
          token:token,ordernum:code
        }, function(result) {
          
            if(result.status=="200"){
             Dialog.alert({
               title: '系统提示',
               message: '核验成功',
             }).then(() => {
               // on close
                that.search();
             });
            }else{
             Dialog.alert({
               title: '系统提示',
               message: result.message,
             }).then(() => {
               // on close
             });
            }
        });
       
     }
   })
 },
 gocheck(){
  wx.navigateTo({
    url: '/pages/index/homecheck',
  })
}
})